import React, { useState, useEffect, useRef } from "react";
import { Space, Table, Tag, message } from "antd";
let data2 = [
  {
    key: "1",
    name: "John Brown",
    age: 32,
    address: "New York No. 1 Lake Park",
    tags: ["nice", "developer"],
  },
  {
    key: "2",
    name: "Jim Green",
    age: 42,
    address: "London No. 1 Lake Park",
    tags: ["loser"],
  },
  {
    key: "3",
    name: "Joe Black",
    age: 32,
    address: "Sydney No. 1 Lake Park",
    tags: ["cool", "teacher"],
  },
];
export default function NormalTable() {
  let [data1, useData1] = useState([]);
  const [messageApi, contextHolder] = message.useMessage();

  let deleteItem = (item) => {
    useData1(data1.filter((i) => i.name !== item.name));
  };

  let InviteItem = (item) => {
    messageApi.info(`Hello, Ant ${item.name}!`);
  };
  const columns1 = [
    {
      title: "Name",
      dataIndex: "name",
      key: "name",
      render: (text) => <a>{text}</a>,
    },
    {
      title: "Age",
      dataIndex: "age",
      key: "age",
    },
    {
      title: "Address",
      dataIndex: "address",
      key: "address",
    },
    {
      title: "Tags",
      key: "tags",
      dataIndex: "tags",
      render: (_, { tags }) => (
        <>
          {tags.map((tag) => {
            let color = tag.length > 5 ? "geekblue" : "green";
            if (tag === "loser") {
              color = "volcano";
            }
            return (
              <Tag color={color} key={tag}>
                {tag.toUpperCase()}
              </Tag>
            );
          })}
        </>
      ),
    },
    {
      title: "Action",
      key: "action",
      render: (_, record) => (
        <Space size="middle">
          <a onClick={() => InviteItem(record)}>Invite {record.name}</a>
          <a onClick={() => deleteItem(record)}>Delete</a>
        </Space>
      ),
    },
  ];

  useEffect(() => {
    useData1(data2);
  }, []);

  return (
    <>
      <Table columns={columns1} dataSource={data1} />
    </>
  );
}
